<?php
class Category extends ORM {

    public $table = 'content_categories';
	
	public $has_one = array(
		'structure',
		'user',
		'layout',
	    'parent' => array(
	        'class' => 'category',
	        'other_field' => 'child'
	    )
	);
	
	public $has_many = array(
	    'child' => array(
			'class' => 'category',
	        'other_field' => 'parent'
	    ),
		'content',
		'board'
	);  

    function __construct($id = NULL)
    {
        parent::__construct($id);
    }
	
	static function child($category)
	{
		switch($category->structure->type)
		{
			case 'agency' : $link = anchor('contents/admin/categories/index/'.$category->id, $category->structure->description); break;
			case 'category' : $link = anchor('contents/admin/categories/index/'.$category->id, $category->structure->description); break;
			//case 'list' : $link = anchor('contents/admin/categories/index/'.$category->id, $category->structure->description); break;
			default : $link = $category->structure->description;
		}
		return $link;
	}
	
}
?>